package com.jake.rabbit.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Queue;

@Aspect
@Slf4j
@Component
public class ConcurrentQueueRemoveAspect {

    @Autowired
    @Qualifier("rabbitConcurrentQueue")
    private Queue<LocalDateTime> rabbitConcurrentQueue;

    @Pointcut("execution(public java.util.Map<String, Object> com.jake.rabbit.controller.RabbitApiController.getResponseMap(..))")
    public void decrease(){}

    @AfterReturning(pointcut = "decrease()")
    public void remove() {
        rabbitConcurrentQueue.poll();
        log.info("release: rabbitConcurrentQueue's size is {}", rabbitConcurrentQueue.size());
    }

}
